package com.hw.graphql.resolver;

import com.hw.graphql.mapper.UserMapper;
import com.hw.graphql.model.User;
import graphql.kickstart.tools.GraphQLQueryResolver;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @program: spring-graphql-x
 * @description: 查询接口
 * @author: hewei
 * @date: 2021-11-12 11:15
 **/

@Slf4j
@Component
public class UserQueryResolver implements GraphQLQueryResolver {

    @Autowired
    private UserMapper userMapper;

    public List<User> userListByName(String nickname) {
        log.info("Query Resolver ==> userListByName");
        log.info("params: nickname:{}", nickname);
        return userMapper.selectByName(nickname);
    }

    public List<User> allUsers() {
        log.info("Query Resolver ==> allUsers");
        return userMapper.selectList(null);
    }
    public User userById(String id) {
        log.info("Query Resolver ==> userById");
        return userMapper.selectById(id);
    }
}